package mapreduce1;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/*
MapReduce 程序读取这三个⽂文件，对三个⽂文件中的数字进⾏行行整体升序排序，并输出到⼀一个结果⽂文件中，结果⽂文件中的每⼀一⾏行行有两个数字（两个数字之间使⽤用制表符分隔)，第⼀一个数字代表排名，第⼆二个数字代表原始数据
 */
public class demoDriver{
    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
        //1. 获取配置文件对象，获取job对象实例
        Configuration configuration = new Configuration();
        Job job = Job.getInstance(configuration);
        //2. 指定程序jar的本地路径
        job.setJarByClass(demoDriver.class);
        //3. 指定Mapper/Reducer类
        job.setMapperClass(demoMapper.class);
        job.setReducerClass(demoReducer.class);
        //4. 指定Mapper输出的kv数据类型
        job.setMapOutputKeyClass(IntWritable.class);
        job.setMapOutputValueClass(NullWritable.class);
        //5. 指定最终输出的kv数据类型
        job.setOutputKeyClass(IntWritable.class);
        job.setOutputValueClass(IntWritable.class);
        //6. 指定job的输入路径
        FileInputFormat.addInputPath(job,new Path("C:\\Users\\wangj01052\\IdeaProjects\\hadoop_project\\src\\main\\resources\\input"));
        //7. 指定job输出结果路径
        FileOutputFormat.setOutputPath(job,new Path("C:\\Users\\wangj01052\\IdeaProjects\\hadoop_project\\src\\main\\resources\\output"));
        //8. 提交作业
        boolean result = job.waitForCompletion(true);
        System.exit(result ? 0 : 1);
    }
}
